package com.sdgakj.web.msg;

import com.sdgakj.entity.MessageUser;
import com.sdgakj.service.msg.MessageUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springside.modules.web.Servlets;

import javax.servlet.ServletRequest;
import java.util.Map;

@Controller
@RequestMapping(value = "/msguser")
public class MsgUserController {

    private static final String PAGE_SIZE = "10";
	
	@Autowired
	private MessageUserService messageUserService;
	
	/**
	 * 列表
	 * @param pageNumber 页号
	 * @param pageSize   每页大小
	 * @param sortType   排序字段
	 * @param model			
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/list",method = RequestMethod.GET)
	public String list(@RequestParam(value = "page", defaultValue = "1") int pageNumber,
			@RequestParam(value = "page.size", defaultValue = PAGE_SIZE) int pageSize,
			@RequestParam(value = "sortType", defaultValue = "auto") String sortType, 
			Model model,ServletRequest request) {
		Map<String,Object> searchParams = Servlets.getParametersStartingWith(request, "search_");
		Page<MessageUser> msgs = messageUserService.getMessage(searchParams, "3", pageNumber, pageSize, "createdate", sortType);
		model.addAttribute("msgs",msgs);
		model.addAttribute("sortType", sortType);
		model.addAttribute("searchParams", Servlets.encodeParameterStringWithPrefix(searchParams, "search_"));
		return "msg/msgUserList";
	}
	
	

}
